<template>
  <div class='photo-info'>
    <van-panel
      :title="imgInfo.title"
      :status="`阅读${imgInfo.click}`"
    >
      <div class="img-box">
        <img
          v-for="(item,index) in thumImgs"
          :key="item.id"
          :src="item.src"
          alt=""
          @click="showImg(index)"
        >
      </div>
      <div class="content">{{imgInfo.content}}</div>
    </van-panel>
    <comment :id="id"></comment>
  </div>
</template>
<script>
import { ImagePreview } from 'vant';
import Comment from "../../../components/Comment"
export default {
  props: ["id"],
  data: () => ({
    imgInfo: {},
    thumImgs: []
  }),
  methods: {
    async getImageInfo() {
      const res = await this.$http.getImageInfo(this.id);
      // console.log(res);
      this.imgInfo = res.data.message;
    },
    async getThumbImages() {
      const res = await this.$http.getThumbImages(this.id);
      console.log(res);
      this.thumImgs = res.data.message;
    },
    showImg(startPosition) {
      var images = [];
      this.thumImgs.forEach(item => { images.push(item.src) })
      // console.log(images);

      //不加startPosition 图片不变，上边的数字也一直都是1
      ImagePreview({
        images,
        startPosition
      });
    }

  },
  created() {
    this.getImageInfo();
    this.getThumbImages();
  },
  components: {
    Comment
  }
}
</script>
<style lang="scss">
.photo-info {
  padding: 0 10px;
  .van-cell__title {
    font-size: 14px;
    flex: 2;
    font-weight: 600;
  }
  .content {
    font-size: 14px;
    text-indent: 2em;
  }
  .img-box {
    display: flex;
    justify-content: space-around;
    margin-bottom: 10px;
    img {
      width: 100px;
      height: 100px;
    }
  }
}
</style>